<?php
    // 管理员添加会员
    header("Access-Control-Allow-Origin: *"); // 允许跨域的地址，* 表示全部
    header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); // 允许的请求方法
    header("Access-Control-Allow-Headers: version, access-token, user-token"); // 允许的请求头属性
    header('Content-Type:application/json');//返回为json

    include "../util/connect.php";

    $Birthday = $_POST["Birthday"];//生日
    $UserName = $_POST['UserName'];//用户名
    $Phone = $_POST["Phone"];//手机号
    $Pwd = $_POST["Password"];//密码
    $User_Role = $_POST['User_Role'];//用户角色
    $User_Intgral = $_POST['User_Intgral'];//用户积分
    $User_Tags = $_POST['User_Tags'];//用户标签
    // $VerifyCode = $_POST['VerifyCode'];//验证码
    date_default_timezone_set('PRC');
    $CreateTime = date("Y-m-d H:i:s");//注册时间

    //生成唯一UserId
    $UserId = uniqid('zt');

    $Pwd1 = $Pwd.'0xz765nb';//加盐拼接
    
    //加密后密码,加盐0xz765nb
    $Password =md5($Pwd1);

    var_dump($User_Role);
    var_dump($User_Intgral);
    var_dump($User_Tags);
    
    //校验验证码
    // session_start();
    // $code = $_SESSION['code'];
    // if ($VerifyCode != $code) {
    //     $arr = [
    //         "status" => 4,
    //         "message" => "验证码错误"
    //     ];
    // }else {
        // if ($Birthday == '' || $Phone == '' || $Password == '' ) {
        //     $arr = [
        //         "status" => 3,
        //         "message" => "注册表单不允许为空"
        //     ];
        // }else {
    
            $sql = " select * from user where Phone='$Phone' ";
            $data = my_Select($sql);
            if($data ){
                $arr = [
                    "status" => 1,
                    "message" => "手机号相同,不能重复注册"
                ];
            }else{
                $sql = "insert into user(UserId,Birthday,UserName,User_Role,User_Intgral,User_Tags,Phone,Password,CreateTime) values('$UserId','$Birthday','$UserName','$User_Role','$User_Intgral','$User_Tags','$Phone','$Password','$CreateTime')";
                $data = my_ZSG($sql);
                if($data){
                    $arr = [
                        "status" => 0,
                        "message" => "注册成功"
                    ];
                }else{
                    $arr = [
                        "status" => 2,
                        "message" => "注册失败"
                    ];
                }
            }
        // }
    // }
   
        




    

    echo json_encode($arr,JSON_UNESCAPED_UNICODE);